home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSSETCUR.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  98 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lssetcur.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STRING
  11. #include <string.h>
  12. #endif
  13.  
  14. /* library headers */
  15. #include <blkio.h>
  16.  
  17. /* local headers */
  18. #include "lseq_.h"
  19.  
  20. /*man---------------------------------------------------------------------------
  21. NAME
  22.      lssetcur - set lseq cursor
  23.  
  24. SYNOPSIS
  25.      #include <lseq.h>
  26.  
  27.      int lssetcur(lsp, lsposp)
  28.      lseq_t *lsp;
  29.      const lspos_t *lsposp;
  30.  
  31. DESCRIPTION
  32.      The lssetcur function sets the current cursor position of lseq
  33.      lsp to the value pointed to by lsposp.  lsposp should point to a
  34.      cursor value saved previously with lsgetcur.  If lsposp is the
  35.      NULL pointer, the cursor is set to null.  It is important to
  36.      remember that an lseq position saved with lsgetcur is not valid
  37.      after that lseq has been unlocked.
  38.  
  39.      lssetcur will fail if one or more of the following is true:
  40.  
  41.      [EINVAL]       lsp is not a valid lseq pointer.
  42.      [LSELOCK]      lsp is not locked.
  43.      [LSENOPEN]     lsp is not open.
  44.  
  45. SEE ALSO
  46.      lsgetcur.
  47.  
  48. DIAGNOSTICS
  49.      Upon successful completion, a value of 0 is returned.  Otherwise,
  50.      a value of -1 is returned, and errno set to indicate the error.
  51.  
  52. ------------------------------------------------------------------------------*/
  53. #ifdef AC_PROTO
  54. int lssetcur(lseq_t *lsp, const lspos_t *lsposp)
  55. #else
  56. int lssetcur(lsp, lsposp)
  57. lseq_t *lsp;
  58. const lspos_t *lsposp;
  59. #endif
  60. {
  61.     /* validate arguments */
  62.     if (!ls_valid(lsp)) {
  63.         errno = EINVAL;
  64.         return -1;
  65.     }
  66.  
  67.     /* check if not open */
  68.     if (!(lsp->flags & LSOPEN)) {
  69.         errno = EINVAL;
  70.         return -1;
  71.     }
  72.  
  73.     /* check locks */
  74.     if (!(lsp->flags & LSLOCKS)) {
  75.         errno = LSELOCK;
  76.         return -1;
  77.     }
  78.  
  79.     /* set new currency */
  80.     if (lsposp == NULL) {
  81.         lsp->clspos = NIL;    /* set cursor to null */
  82.     } else {
  83.         memcpy(&lsp->clspos, lsposp, sizeof(lsp->clspos));
  84.     }
  85.  
  86.     /* read in new current record */
  87.     if (lsp->clspos == NIL) {
  88.         ls_rcinit(lsp, lsp->clsrp);
  89.     } else {
  90.         if (ls_rcget(lsp, lsp->clspos, lsp->clsrp) == -1) {
  91.             LSEPRINT;
  92.             return -1;
  93.         }
  94.     }
  95.  
  96.     return 0;
  97. }
  98.